package com.hopes.bizz.common.core.util;

import cn.hutool.core.util.StrUtil;

/**
 * @author daijie
 * @version 1.0
 * @date 2023/5/19 11:10
 * @Description:
 */
public class StringUtils extends StrUtil {

    public static boolean isNotBlank(Object obj) {
        if (null == obj) {
            return false;
        } else {
            return !isBlank(String.valueOf(obj));
        }
    }

    public static String getUseFlagStr(Boolean useFlag) {
        if (useFlag) {
            return "是";
        } else {
            return "否";
        }
    }

    public static Boolean getUseFlag(String useFlag) {
        return "是".equals(useFlag);
    }


    public static boolean containsAllCharFromStr(String source, String target) {
        if (StringUtils.isEmpty(source)) {
            return false;
        }
        final char[] chars = new char[target.length()];
        for (int i = 0; i < target.length(); i++) {
            chars[i] = target.charAt(i);
        }
        return containsAllChars(source, chars);
    }

    /**
     * 判断 source 是否包含 chars 中的每一个字符
     * @param source   源
     * @param chars   目标
     * @return         结果
     */
    public static boolean containsAllChars(String source, char[] chars) {
        for (char ch : chars) {
            final int i = source.indexOf(ch);
            if (i == -1) {
                return false;
            }
        }
        return true;
    }
}
